<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');

	class m_AdminUsers extends CI_Model
	{
		function __construct()
    	{
    	    // Call the Model constructor
    	    parent::__construct();
    	}
		
		function get_users()
		{
			$this->load->database();
			$this->load->library('Datatables'); 
			$this->datatables->select('tblUser.userId, tblUser.userEmail, tblUserProfile.firstName, tblUserProfile.lastName, tblUser.userStatus')->from('tblUser')->join('tblUserProfile', 'tblUser.userId = tblUserProfile.userId', 'left');
			$query = $this->datatables->generate();
			return $query;
		}
		
		function set_userid($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'userId' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblUserProfile', $data); 
			
			$data = array(
						   'userId' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblUser', $data);
			
			$data = array(
						   'userId' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblVendorLinks', $data);
		}

		function set_email($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'userEmail' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblUser', $data); 
		}
		
		function set_fname($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'firstName' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblUserProfile', $data); 
		}
		
		function set_lname($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'lastName' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblUserProfile', $data); 
		}
		
		function updateclosed($closed, $userId)
		{
			$this->load->database();
			
			$data = array(
						   'userStatus' => $closed
						);

			$this->db->where('userId', $userId);
			$this->db->update('tblUser', $data); 
		}
	}
?>
